 /***************************************************************************
 *   Copyright (C) 2010 by ZhangShine , All Rights Reserved                                  
 *   zhangshine0125@gmail.com                                              
 *                                                                         
 *   This program is free software; you can redistribute it and/or modify  
 *   it under the terms of the GNU General Public License as published by  
 *   the Free Software Foundation; either version 2 of the License, or     
 *   (at your option) any later version.                                   
 *                                                                         
 *   This program is distributed in the hope that it will be useful,       
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         
 *   GNU General Public License for more details.                          
 *                                                                         
 *   You should have received a copy of the GNU General Public License     
 *   along with this program; if not, write to the                         
 *   Free Software Foundation, Inc.,                                       
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             
 ***************************************************************************/

#include "configuredialog.h"
#include "ui_configuredialog.h"

ConfigureDialog::ConfigureDialog(QString id, QWidget *parent) :
    QDialog(parent),
    ui(new Ui::ConfigureDialog)
{
    ui->setupUi(this);
    this->id = id;
    this->setWindowTitle(tr("设置"));
    this->conf = Configuration::getInstance();
    //refresh time
    ui->spinBox_updatetime->setRange(60, 600);//60s-600s
    ui->spinBox_updatetime->setValue(conf->getAccountConf(id, conf->updateStatusS));
    //home page 
    ui->spinBox_homepagecount->setRange( 5, 100);
    ui->spinBox_homepagecount->setValue(conf->getAccountConf(id, conf->homeCS));
    //myweibo page
    ui->spinBox_myweibocount->setRange(5, 100);
    ui->spinBox_myweibocount->setValue(conf->getAccountConf(id, conf->userWeiboCS));
    //atme page
    ui->spinBox_atmecount->setRange( 5, 100);
    ui->spinBox_atmecount->setValue(conf->getAccountConf(id, conf->atMeCS));
    //comment page
    ui->spinBox_commentmecount->setRange( 5, 100);
    ui->spinBox_commentmecount->setValue(conf->getAccountConf(id, conf->commentCS));
//    //favorite page   sina default configration is 20
//    ui->spinBox_myfavoritecount->setRange( 5, 100);
//    ui->spinBox_myfavoritecount->setValue(conf->getAccountConf(id, conf->favoriteCS));
    //direct message
    ui->checkBox_isNotify->setChecked(conf->settings->value(id+"/"+conf->isNotifyCS, true).toBool());
    
    ui->spinBox_directmessage->setRange( 5, 100);
    ui->spinBox_directmessage->setValue(conf->getAccountConf(id, conf->directMessageCS));
    QObject::connect(ui->pushButton_ok, SIGNAL(clicked()), this, SLOT(saveConf()));
    QObject::connect(ui->pushButton_cancel, SIGNAL(clicked()), this, SLOT(cancel()));
}

ConfigureDialog::~ConfigureDialog()
{
    delete ui;
}

void ConfigureDialog::saveConf()
{
    conf->saveAccountConf(id, ui->spinBox_homepagecount->value(), ui->spinBox_atmecount->value(),
                          ui->spinBox_myweibocount->value(), ui->spinBox_commentmecount->value(),
                          ui->spinBox_directmessage->value(), ui->spinBox_updatetime->value());
    conf->settings->beginGroup(id);
    conf->settings->setValue(conf->isNotifyCS, ui->checkBox_isNotify->isChecked());
    conf->settings->sync();
    conf->settings->endGroup();
    this->accept();
}

void ConfigureDialog::cancel()
{
    this->reject();
}
